
package work02.shop;

/**
 * @author sunlggggg
 * @date 2017/4/16
 */
public class ShopCar {
    private int capacity = 100 ;

    int amount;

    public ShopCar() {
        amount = 0 ;
    }

    public ShopCar(int amount) {
        this.amount = amount;
    }

    public int getAmount() {
        return amount;
    }

    public void addCommodityAmount(int amount) throws CarFullException {
        int nowAmount  = this.amount += amount;
        if(nowAmount > capacity )
            throw new CarFullException("this car is full");
        this.amount = nowAmount;
    }

    public void removeCommodityAmount(int amount) throws CarEmptyException {
        int nowAmount = this.amount - amount;
        if(nowAmount < 0 ){
            throw  new CarEmptyException("this car is empty");
        }
        this.amount -= amount;
    }
}
